
define(['angular',"text!www/article/article_list.html",'url','common'], function (angular,tpl) {
    //angular会自动根据controller函数的参数名，导入相应的服务
   function controller($scope,$rootScope,$http,$routeParams){
	    showSpin();
		rightMenu();
		var Articlelist = function (cat_id) {
	    	 this.cat_id= cat_id;
	         this.items = [];
	         this.busy = false;
	         this.baseUrl = ip+"/";
	         this.page = 1;
	     };
		$scope.Articlelist = new Articlelist($routeParams.catId);
		$scope.Articlelist.nextPage = function () {
				if(this.page!=1){
				   if(!isFooter()) return ;
			   }
	         if (this.busy) return;
	         this.busy = true;
	         var pro = this;
	         var url = cl.getArticleListUrl+"&callback=JSON_CALLBACK&page="+ this.page+"&cat_id="+this.cat_id ;
	         $http.jsonp(url).success(function (res) {
	        	 if(res.code=="CL02011"){
	        		 if(res.result.article_list.length!=0){
	        			// console.info(res.result.article_list);
			             var items = res.result.article_list;
			             for (var i = 0; i < items.length; i++) {
			            	 pro.items.push(items[i]);
			             }
			             pro.page += 1;
					}
	        	 }else if(res.code=="CL020012"){
	        		 
	        	 }
	        	 if(pro.items.length==0){
		      		   $rootScope.changeNull();
		      	  }else{
		      		  $rootScope.hideNull();
		      	  }
	        	 pro.busy = false;
	             hideSpin();
	         });
	     };
		
		$scope.Articlelist.nextPage();
    };
    return {controller:controller,tpl:tpl};
});
